import service, { config } from "./service";
import { AxiosResponse } from "axios";

const http_request = <T = any, D = any, R = AxiosResponse<T, D>>(url: string, option?: AxiosRequestOptions<D>): Promise<R> => {
    let _option = { ...option };
    return service(url, {
        method: _option?.method,
        params: _option?.params,
        data: _option?.data,
        responseType: _option?.responseType,
        headers: {
            "Content-Type": option?.headersType || config.defaultContentType,
        },
    });
};

export default {
    get: <T = any, D = any, R = AxiosResponse<T, D>>(url: string, option?: AxiosRequestOptions<D>): Promise<R> => {
        return http_request(url, { method: "get", ...option });
    },

    post: <T = any, D = any, R = AxiosResponse<T, D>>(url: string, option?: AxiosRequestOptions<D>): Promise<R> => {
        return http_request(url, { method: "post", ...option });
    },

    put: <T = any, D = any, R = AxiosResponse<T, D>>(url: string, option?: AxiosRequestOptions<D>): Promise<R> => {
        return http_request(url, { method: "put", ...option });
    },

    delete: <T = any, D = any, R = AxiosResponse<T, D>>(url: string, option?: AxiosRequestOptions<D>): Promise<R> => {
        return http_request(url, { method: "delete", ...option });
    },
};

/*
export interface AxiosRequestConfig<D = any> {
  url?: string;
  method?: Method | string;
  baseURL?: string;
  transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
  transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
  headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
  params?: any;
  paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
  data?: D;
  timeout?: Milliseconds;
  timeoutErrorMessage?: string;
  withCredentials?: boolean;
  adapter?: AxiosAdapterConfig | AxiosAdapterConfig[];
  auth?: AxiosBasicCredentials;
  responseType?: ResponseType;
  responseEncoding?: responseEncoding | string;
  xsrfCookieName?: string;
  xsrfHeaderName?: string;
  onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
  onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
  maxContentLength?: number;
  validateStatus?: ((status: number) => boolean) | null;
  maxBodyLength?: number;
  maxRedirects?: number;
  maxRate?: number | [MaxUploadRate, MaxDownloadRate];
  beforeRedirect?: (options: Record<string, any>, responseDetails: {headers: Record<string, string>}) => void;
  socketPath?: string | null;
  transport?: any;
  httpAgent?: any;
  httpsAgent?: any;
  proxy?: AxiosProxyConfig | false;
  cancelToken?: CancelToken;
  decompress?: boolean;
  transitional?: TransitionalOptions;
  signal?: GenericAbortSignal;
  insecureHTTPParser?: boolean;
  env?: {
    FormData?: new (...args: any[]) => object;
  };
  formSerializer?: FormSerializerOptions;
}



*/
